<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="/bower_components/bootstrap/dist/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="/stylesheets/admin.css">
	<script type="text/javascript" src="//cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
	<script type="text/javascript" src="/bower_components/upload-jquery/jquery.upload.js"></script>

</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-xs-8 col-xs-offset-2">
				<div class="page-header">
					<h3>添加文章<a href="articleLists" class="pull-right"><返回</a></h3>
				</div>
				<div class="error"><%= success %></div>
				<form action="/admin/addArticles" enctype="multipart/form-data" method="post">
					<div class="form-group">
						
						<label>文章标题：</label>

						<span class="error"><%= title_error %></span>
						
						<input type="text" name="title" class="form-control" placeholder="请输入文章标题">
					</div>
					<div class="form-group">
						<label>
							图片上传：
							<button type="button" class="btn btn-info btn-xs" onclick="doUpload()">点击上传</button>
							<span class="error"><%= image_error %></span>
						</label>
						<!-- <input type="file" name="images"> -->
						<div class="row">
							<div class="col-xs-10">
								<img id="image_preview" />
								<input id="image" type="hidden" name="images" class="form-control">
							</div>
						</div>

					</div>
					<div class="form-group">
						<label>分类id：<span class="error"><%= cataId_error %></span></label>
						<select name="cata_id" class="form-control">
							<option value="$">----------请选择分类----------</option>
							<% for(var i=0;i<rows.length;i++){ %>
							<option value="<%= rows[i].id%>"><%= rows[i].name%></option>
							<% } %>
						</select>

					</div>
					<div class="form-group">
						<label>文章内容：<span class="error"><%= content_error %></span></label>
						<textarea class="form-control" name="content" placeholder="请输入文章内容"></textarea>
					</div>
						<button id="submit" type="submit" class="btn btn-success">提交</button>
				</form>
			</div>
		</div>
		
	</div>
</body>
</html>

<script type="text/javascript">
 		
	/*jQuery插件上传文件*/
	function doUpload() {
	// 上传方法
	$.upload({
			// 上传地址
			url: '/admin/uploadFile', 
			// 文件域名字
			fileName: 'fileInput', 
			// 其他表单数据
			params: {},
			// 上传完成后, 返回json, text
			dataType: 'text',
			// 上传之前回调,return true表示可继续上传
			onSend: function() {
					return true;
			},
			// 上传之后回调
			onComplate: function(data) {
					$('#image').val(data);
					$('#image_preview').attr("src",data);
			}
	});
}
	/*客户端表单验证*/
	/*$('#submit').click(function(){
		if ($('input[name="title"]').val()=='') {
			alert("文章标题不能为空");
			return false;
		}
	})*/


	// connect-flash表单验证

	setTimeout(function(){
		$('.error').fadeOut(1000);
	},3000)

</script>